package ru.firststeps.speedtest;

import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListAdapter;
import android.widget.SimpleCursorAdapter;

public class ViewDBActivity extends ListActivity {
    private Cursor cursor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        cursor = managedQuery(DataProvider.CONTENT_URI, new String[]{
                DataDBHelper._ID, DataDBHelper.CONNECTION_TYPE, DataDBHelper.OPERATOR, DataDBHelper.SPEED, DataDBHelper.LATITUDE,
                DataDBHelper.LONGITUDE}, null, null, null);
        ListAdapter adapter = new SimpleCursorAdapter(this, R.layout.view_db,
                cursor, new String[]{DataDBHelper.CONNECTION_TYPE, DataDBHelper.OPERATOR, DataDBHelper.SPEED,
                DataDBHelper.LATITUDE, DataDBHelper.LONGITUDE},
                new int[]{R.id.connection_type, R.id.operator, R.id.speed, R.id.latitude, R.id.longitude});
        setListAdapter(adapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.view_db_menu, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.back:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }


}
